package com.itheima.mapper.store;

import com.itheima.domain.store.Product;
import jdk.nashorn.internal.ir.annotations.Reference;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ProductMapper {


    @Select("select * from product")
    @Results(id = "productMap",value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "DepartureTime",property = "departureTimeStr")
    })
    List<Product> list();

    //新增
    @Insert("insert into product (id,productNum,productName,DepartureTime,cityName,productPrice,productStatus,productDesc)" +
            "values(#{id},#{productNum},#{productName},#{departureTimeStr},#{cityName},#{productPrice},#{productStatus},#{productDesc})")
    void save(Product product);

    //删除)
    @Delete("delete from product where id=#{ids}")
    void deleteByIds(String ids);



    //通过id查询
    @Select("select * from product where id = #{id}")
    @ResultMap("productMap")
    Product findById(String id);

    //编辑
    @Update("update product set productNum=#{productNum},productName=#{productName},DepartureTime=#{departureTimeStr}," +
            "cityName=#{cityName},productPrice=#{productPrice},productStatus=#{productStatus},productDesc=#{productDesc} where id=#{id}")
    void edit(Product product);

    //改状态
    @Update("update product set productStatus='1' where id=#{s}")
    void toon(String s);


    //编辑
    @Update("update product set productStatus='0' where id=#{s}")
    void tooff(String s);

    //pid拿到oid
    @Select("select id from orders where productId=#{ids}")
    List<String> findOidByPid(String ids);

    //oid删除traveller
    @Delete("delete from order_traveller where orderId=#{oid}")
    void deleteTraByOid(String oid);

    //返回所有的城市
    @Select("select distinct cityName from product ")
    List<String> findAllCity();

    //模糊查询
    @Select("select * from product where productName like #{lms}")
    List<Product> likeFindAll(String lms);

//    //
//    @Select("select * from product where id=#{id}")
//    @ResultMap("productMap")
//    Product selectStatus(String id);
}
